package br.com.season.collections;

public class Customer implements Comparable {
	
	private int id;
	private String name;
	
	public Customer (int id, String name){
		super();
		this.id=id;
		this.name=name;
	}
		
	//crtl 3 toString
	
	@Override
	public String toString() {
		return "Customer [id=" + id + ", name=" + name + "]";
	}
	
	//crtl 3 hash
	@Override
	public int hashCode() {
		
		final int prime = 31;
		int hash = 1;
		hash += (prime*id);
		hash += (prime*name.hashCode());
		return hash;
	
	}
	
	//crtl 3 equals
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Customer other = (Customer) obj;
		if (id != other.id)
			return false;
		if (name == null) {
			if (other.name != null)
				return false;
		} else if (!name.equals(other.name))
			return false;
		return true;
	}
	
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}

	/**
	 * 
	 * == 0 é igual
	 * > 0 é maior
	 * < 0 menor
	 * (non-Javadoc)
	 * @see java.lang.Comparable#compareTo(java.lang.Object)
	 * 
	 */

	
	@Override
	public int compareTo(Object object) {
		
		if (object == null) return 1;
		if (!(object instanceof Customer)) return -1;
		if ( object == this ) return 0;
		
		Customer other = (Customer) object;
		
		return (id - other.getId());
		//return (id - other.Id()); Quando mesma classe
		
	}
	

}
